package exam.service.impl;

import exam.dao.UserDao;
import exam.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.ImportResource;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
import javax.annotation.Resource;

//<bean id="userService" class="exam.service.impl.UserServiceImpl">
//@Component("userService")
@Service("userService")
//@Scope("prototype")
@Scope("singleton")
public class UserServiceImpl implements UserService {
//    @Value("${jdbc.driver}")
    @Value("weirdlight")
    private String driver;

    //<property name="userDao" ref="userDao"/>
    @Autowired //按照数据类型从spring容器中匹配
    @Qualifier("userDao")//是按照id名称从容器中匹配,但是此处@Qualifier要结合@Autowired一起使用
//    @Resource(name="userDao")//@Resource相当于@Qualifier + @Autowired
    private UserDao userDao;

    //通过注解方式set方法可以省略不写
/*    public void setUserDao(UserDao userDao) {
        this.userDao = userDao;
    }*/

    @Override
    public void save() {
        System.out.println(driver);
        userDao.save();
    }
    @PostConstruct
    public void init(){
        System.out.println("Service的对象的初始化方法");
    }
    @PreDestroy
    public void destroy(){
        System.out.println("Service的对象的销毁方法");
    }
}
